package com.emergency.db.controller.staff;

import com.emergency.common.entity.Result;
import com.emergency.common.entity.StatusCode;
import com.emergency.db.domain.staff.StaffDetail;
import com.emergency.db.domain.staff.StaffLocation;
import com.emergency.db.service.staff.StaffLocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
@RequestMapping("/staff/location")
@CrossOrigin
public class StaffLocationController {

    @Autowired
    private StaffLocationService staffLocationService;


    //保存
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result save(@RequestBody StaffLocation staffLocation) {
        Long id = staffLocationService.save(staffLocation);
        return new Result(true, StatusCode.OK, "保存成功", id);
    }

    //删除
    @RequestMapping(value = "/del/{id}", method = RequestMethod.POST)
    public Result del(@PathVariable("id") Long id) {
        staffLocationService.deleteAllByStaff(id);
        return new Result(true, StatusCode.OK, "删除成功");
    }

    //分页
    @RequestMapping(value = "/list/{id}/{page}/{size}", method = RequestMethod.POST)
    public Result list(@RequestBody Map searchMap, @PathVariable Long id, @PathVariable int page, @PathVariable int size) {
        Page<StaffLocation> pageList = staffLocationService.findList(searchMap, page, size, id);
        return new Result(true, StatusCode.OK, "操作成功", pageList);
    }

}
